package com.servlet.request;
/**
 * @author wzm
 * @create 2023-11-04 16:40
 * project_name:web2310
 * @Description
 */

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/req4")
public class RequestServlet4 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(request);
//        RequestFacade
        
        //1.获取请求方式
        String method = request.getMethod();
        System.out.println("method = " + method);
        //2.获取项目的访问路径（虚拟目录）
        String contextPath = request.getContextPath();
        System.out.println("contextPath = " + contextPath);//web04

        //3.获取项目URL(统一资源定位符)
        StringBuffer requestURL = request.getRequestURL(); //http://localhost:8080/web04/req4
        System.out.println(requestURL.toString());

        //4.获取项目的URI(统一资源标识符)
        String requestURI = request.getRequestURI();
        System.out.println("requestURI = " + requestURI);///web04/req4
        
        //5.获取请求参数
        String queryString = request.getQueryString();
        System.out.println("queryString = " + queryString);

        //6.获取请求头信息
        String header = request.getHeader("User-Agent");//浏览器的版本信息
        System.out.println("header = " + header);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("post...");
        //7.针对Post请求获取请求体数据

        //前端传过来的是纯文本
        //7.1.获取字符输入流
        BufferedReader reader = request.getReader();
        //7.2.读取流中数据
        String s = reader.readLine();
        System.out.println("s = " + s);

        //前端传输的是文件
        //获取字节输入流
        ServletInputStream inputStream = request.getInputStream();

    }
}
